﻿using UnityEngine;
using System.Collections;

public class ChangeLevel : MonoBehaviour 
{

    private bool bLoadLevel = false;

    private float counter = 0;
    private float fadeTime = 1.0f;
    private string levelToLoad = "";

    public GameObject fadeObject = null;

    public void LoadLevel(string level)
    {
        Time.timeScale = 1.0f;
        Application.LoadLevel(level);
    }

    public void LoadLevelFade(string level)
    {
        if (fadeObject != null)
            fadeObject.SetActive(true);

        Time.timeScale = 1.0f;
        bLoadLevel = true;
        levelToLoad = level;
    }

    void Update()
    {
        if (bLoadLevel)
        {
            counter += Time.deltaTime;

            if (counter > fadeTime)
            {
                counter = 0;
                bLoadLevel = false;
                Application.LoadLevel(levelToLoad);
            }
        }
    }

   

}
